package com.study.dao.impl;

import com.study.dao.AppCategoryDao;
import com.study.entity.AppCategory;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by Administrator on 2017/10/25.
 */
@Repository
public class AppCategoryDaoImpl implements AppCategoryDao {
    @Autowired
    private HibernateTemplate hibernateTemplate;
    @Override
    public AppCategory findOneById(Integer id) {
        return hibernateTemplate.get(AppCategory.class,id);
    }

    @Override
    public List<AppCategory> findList(AppCategory appCategory) {
        return null;
    }

    @Override
    public int updateOne(AppCategory appCategory) {
        return 0;
    }

    @Override
    public int saveOne(AppCategory appCategory) {
        return 0;
    }

    @Override
    public int deleteById(Integer id) {
        return 0;
    }

    @Override
    public List<AppCategory> findListByPid(Integer pid) {
        Session session = hibernateTemplate.getSessionFactory().openSession();
        String hql="from AppCategory where parentId=?";
        Query query = session.createQuery(hql);
        query.setParameter(0,pid);
        query.setCacheable(true);
        return query.list();
        /*AppCategory appCategory=new AppCategory();
        appCategory.setParentId(pid);
        return hibernateTemplate.findByExample(appCategory);*/
    }
}
